<?php
defined('IN_TS') or die('Access Denied.');
class ask extends tsApp{

	//构造函数
	public function __construct($db){
		parent::__construct($db);
	}
	
	//问题分类数增1
	function add_cate_one($cateid)
	{
		$cateid = intval($cateid);
		$this->db->query("update ".dbprefix."ask_cate set count_topic = count_topic + 1 where cateid = ".$cateid);
	}
	
	//问题分类数减1
	function reduce_cate_one($cateid)
	{
		$cateid = intval($cateid);
		$this->db->query("update ".dbprefix."ask_cate set count_topic = count_topic - 1 where cateid = ".$cateid);
	}
	
	//答案数增1
	function add_ask_one($askid)
	{
		$askid = intval($askid);
		$this->db->query("update ".dbprefix."ask_topic set count = count + 1 where askid = ".$askid);
	}
	
	//答案数减1
	function reduce_ask_one($askid)
	{
		$askid = intval($askid);
		$this->db->query("update ".dbprefix."ask_topic set count = count - 1 where askid = ".$askid);
	}
	
	//回复支持数增1
	function add_comment_one($commentid)
	{
		$commentid = intval($commentid);
		$this->db->query("update ".dbprefix."ask_comment set digg = digg + 1 where commentid = ".$commentid);
	}
	
	//回复反对数增1
	function opp_comment_one($commentid)
	{
		$commentid = intval($commentid);
		$this->db->query("update ".dbprefix."ask_comment set undigg = undigg + 1 where commentid = ".$commentid);
	}
	
	//用户积分增1
	function add_userscore_one($userid)
	{
		$scorearr = $this->find('ask_user_score', array('userid'=>$userid));
		if ($scorearr)
		{
			$score = $scorearr['score'] + 1;
			$this->update('ask_user_score', array('userid'=>$userid), array('score'=>$score));
			return;
		}
		$this->create('ask_user_score', array('userid'=>$userid, 'score'=>1));
	}
	
	//用户积分减1
	function reduce_userscore_one($userid)
	{
		$scorearr = $this->find('ask_user_score', array('userid'=>$userid));
		if ($scorearr)
		{
			$score = $scorearr['score'] - 1 < 0 ? 0 : $scorearr['score'] - 1;
			$this->update('ask_user_score', array('userid'=>$userid), array('score'=>$score));
			return;
		}
	}
	
}